package com.cn.jinl.controller;


import com.cn.jinl.api.IBoxManageService;
import com.cn.jinl.domain.BoxManage;
import com.cn.jinl.domain.BoxManageVo;
import com.cn.jinl.domain.ScanCodeVo;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/box")
public class BoxManageController {

    @Autowired
    private IBoxManageService boxManageService;


    @RequestMapping("/getBoxManageList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<BoxManage>> getBoxManageList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<BoxManage>> response = new JsonResponse<List<BoxManage>>();
        List<BoxManage> list  = boxManageService.getBoxManageList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    @ResponseBody
    @RequestMapping("/api/addBoxManage")
    public JsonResponse<String> addBoxManage(BoxManage boxManage) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = boxManageService.addBoxManage(boxManage);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateBoxManage/{frontToken}")
    public JsonResponse<String> updateBoxManage(@RequestBody List<BoxManage> boxManages, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = boxManageService.updateBoxManage(boxManages);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateEmptyPrintBox/{frontToken}")
    public JsonResponse<String> updateEmptyPrintBox(@RequestBody List<BoxManage> boxManages, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = boxManageService.updateEmptyPrintBox(boxManages);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateRepeatPrintBox/{frontToken}")
    public JsonResponse<String> updateRepeatPrintBox(@RequestBody List<BoxManage> boxManages, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = boxManageService.updateRepeatPrintBox(boxManages);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/updateBatchRepeatPrintBox/{frontToken}")
    public JsonResponse<String> updateBatchRepeatPrintBox(BoxManage boxManage, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = boxManageService.updateBatchRepeatPrintBox(boxManage);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/api/scanBoxInfo")
    public JsonResponse<String> updateBoxManage(String boxCode,String itemTypeId,String gradeValue) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = boxManageService.scanBoxInfo(boxCode,itemTypeId,gradeValue);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/api/scanTuiHuoBoxInfo")
    public JsonResponse<String> updateTuHuoBoxManage(String boxCode) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = boxManageService.scanTuiHuoBoxInfo(boxCode);
        return CommonUtil.getResponseData(response,result);
    }


    //扫码识别接口
    @RequestMapping("/getScanCodeInfo")
    @ResponseBody
    public JsonResponse<ScanCodeVo> getScanCodeInfo(@RequestBody ScanCodeVo scanCodeVo) throws Exception{
        JsonResponse<ScanCodeVo> response = new JsonResponse<>();
        ScanCodeVo scanCodeVos = boxManageService.getDetailByBoxCode(scanCodeVo);
        response.setResult(scanCodeVos);
        response.setSuccess(true);
        return response;
    }


    //---------------------------------------------------箱码管理新页面接口------------------------------------

    //列表
    @RequestMapping("/getNewBoxManageList/{frontToken}")
    @ResponseBody
    public JsonResponse<List<BoxManage>> getNewBoxManageList(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<BoxManage>> response = new JsonResponse<List<BoxManage>>();
        List<BoxManage> list  = boxManageService.getNewBoxManageList(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    //批量作废
    @ResponseBody
    @RequestMapping("/voidBoxManage/{frontToken}")
    public JsonResponse<String> voidBoxManage(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = boxManageService.voidBoxManage(queryForm);
        return CommonUtil.getResponseData(response,result);
    }

    //批量打印
    @ResponseBody
    @RequestMapping("/batchBoxManage/{frontToken}")
    public JsonResponse<String> batchBoxManage(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken ) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = boxManageService.batchBoxManage(queryForm);
        return CommonUtil.getResponseData(response,result);
    }

    //查看
    @RequestMapping("/getBoxManageListById/{frontToken}")
    @ResponseBody
    public JsonResponse<BoxManageVo> getBoxManageListById(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<BoxManageVo> response = new JsonResponse<BoxManageVo>();
        BoxManageVo list  = boxManageService.getBoxManageListById(queryForm);
        response.setResult(list);
        response.setSuccess(true);
        return  response;
    }

    //破损补打查询接口
    @RequestMapping("/getReprintListById/{frontToken}")
    @ResponseBody
    public JsonResponse<BoxManageVo> getReprintListById(@RequestBody QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<BoxManageVo> response = new JsonResponse<BoxManageVo>();
        BoxManageVo boxManageVo  = boxManageService.getReprintListById(queryForm);
        response.setResult(boxManageVo);
        response.setSuccess(boxManageVo.getMsg() == null || boxManageVo.getMsg().isEmpty());
        return  response;
    }
}
